import moment from 'moment';
import { $l } from '@choerodon/boot';

export default {
  primaryKey: 'recordId',
  name: 'ApiInvokeRecord',
  autoQuery: true,
  selection: false,
  pageSize: 20,
  fields: [
    { name: 'recordId', type: 'number', label: 'recordId' },
    { name: 'apiUrl', type: 'string', label: $l('interface.lind.interfaceurl') },
    { name: 'invokeId', type: 'string', label: $l('api.invokerecord.invokeid') },
    { name: 'applicationCode', type: 'string', label: $l('api.application.code') },
    { name: 'serverCode', type: 'string', label: $l('server.code') },
    { name: 'serverName', type: 'string', label: $l('server.name') },
    { name: 'clientId', type: 'string', label: $l('interface.clientid') },
    { name: 'requestTime', type: 'string', label: $l('hapinterfaceoutbound.requesttime') },
    { name: 'startDate', type: 'string', label: $l('hapinterfaceinbound.startdate') },
    { name: 'ip', type: 'string', label: 'IP' },
    { name: 'requestMethod', type: 'string', label: $l('interface.requestmethod') },
    { name: 'apiResponseTime', type: 'number', label: $l('api.invokerecord.apiresponsetime') },
    { name: 'responseTime', type: 'number', label: $l('api.invokerecord.responsetime') },
    { name: 'interfaceType', type: 'string', label: $l('interface.interfacetype') },
    { name: 'responseStatus', type: 'string', label: $l('interface.invoke.requeststatus'), lookupCode: 'SYS.IF.REQUEST_STATUS' },
    { name: 'requestUrl', type: 'string', label: $l('api.invokerecord.requesturl') },
    { name: 'userAgent', type: 'string', label: $l('interface.invoke.useragent') },
    { name: 'referer', type: 'string', label: $l('interface.invoke.userreferer') },
    { name: 'apiInvokeRecordDetails', type: 'object' },
    {
      name: 'apiRequestBodyParameter',
      type: 'string',
      label: $l('api.invokerecord.apirequestbodyparameter'),
      bind: 'apiInvokeRecordDetails.apiRequestBodyParameter',
    },
    {
      name: 'apiResponseContent',
      type: 'string',
      label: $l('api.invokerecord.apiresponsecontent'),
      bind: 'apiInvokeRecordDetails.apiResponseContent',
    },
    {
      name: 'requestBodyParameter',
      type: 'string',
      label: $l('api.invokerecord.requestbodyparameter'),
      bind: 'apiInvokeRecordDetails.requestBodyParameter',
    },
    { name: 'responseContent', type: 'string', label: $l('api.invokerecord.responsecontent'), bind: 'apiInvokeRecordDetails.responseContent' },
    { name: 'stacktrace', type: 'string', label: $l('api.invokerecord.info'), bind: 'apiInvokeRecordDetails.stacktrace' },
  ],
  queryFields: [
    { name: 'applicationCode', type: 'string', label: $l('api.application.code') },
    { name: 'clientId', type: 'string', label: $l('interface.clientid') },
    {
      name: 'startDate',
      type: 'dateTime',
      label: $l('hapinterfaceinbound.startdate'),
      defaultValue: moment().clone().set({ hour: 0, minute: 0, second: 0, millisecond: 0 }),
    },
    { name: 'invokeId', type: 'string', label: $l('api.invokerecord.invokeid') },
    { name: 'serverCode', type: 'string', label: $l('server.code') },
    { name: 'responseStatus', type: 'string', label: $l('interface.invoke.requeststatus'), lookupCode: 'SYS.IF.REQUEST_STATUS' },
  ],
};
